﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Entity
{
    public class SMDBContext:DbContext
    {
        public SMDBContext()
        {

        }
        /// <summary>
        /// 创建一个只读的_ConnectionString
        /// </summary>
        private readonly string? _ConnectionString;

        /// <summary>
        /// 获取_ConnectionString
        /// </summary>
        /// <param name="opts"></param>
        /// <param name="configuration"></param>
        public SMDBContext(DbContextOptions<SMDBContext> opts,IConfiguration configuration) : base(opts)
        {
            _ConnectionString = configuration.GetConnectionString("AIYDB_Mysql");
        }
        /// <summary>
        /// 账户
        /// </summary>
        public DbSet<EntityAccount> EntityAccount { get; set; }
        /// <summary>
        /// 用户信息
        /// </summary>
        public DbSet<EntityUserInfo> EntityUserInfo { get; set; }
        /// <summary>
        /// 报名表
        /// </summary>
        public DbSet<EntityAddName> EntityAddName { get; set; }

        
        /// <summary>
        /// 第一个配置
        /// </summary>
        /// <param name="optionsBuilder"></param>
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySql(_ConnectionString, new MySqlServerVersion(new Version(9, 2, 0)));
        }

        /// <summary>
        /// 第二个
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasCharSet("utf8mb4").UseGuidCollation("utf8mb4_german2_ci");
        }
    }
}
